{include file='fcworker/fc_head'}
<style>
    .text-right{
        text-align: right;
        font-size: 12.5px;
        color: #333;
    }
    .group_tips{
         font-size: 12.5px;
         color: #666666;
     }
    /*.input-border{*/
    /*    border: 1px solid black !important;*/
    /*    border-radius: 6px;*/
    /*}*/
    .btn-div{
        width: 100%;
        text-align: center;
        margin: 0 auto;
    }
    .btn{
        width: 184px;
        height: 35px;
        background-color: #5c99f7;
        border-radius: 50px;
        border: 0;
        margin-top: 20px;
        color: #fff;
        font-size: 15px;
        font-weight: 400;
    }
    .martop60{
        margin-top: 60px;
    }
    .martop80{
        margin-top: 80px;
    }
    .upload-img-li>div{
        margin: 0 auto;
    }
    .i_header{
        width: 100%;
        height: 188px;
        background: url(https://css2020.yixuan.net/2019css/yxworker/tempcss/images/index_01.png) no-repeat;
        text-align: center;
        padding-top: 30px;
        box-sizing: border-box;
        background-size: 100% 100%;
    }
    .i_header .s_head{
        width: 70px;
        height: 70px;
        border: 2.5px solid #ffffff;
        margin: 0.5px auto;
        border-radius: 50%;
    }
    .i_header .h3{
        font-size: 14px;
        height: 22.5px;
        line-height: 22.5px;
        color: #ffffff;
    }
    .qr_code{
        height: 320px;
        width: 320px;
    }
    .shuoming{
        text-align: center;
        height: 38px;
        line-height: 18px;
        font-size: 13px;
        color: #333;
    }
    .item{
        text-align: center;
        height: 100px;
    }
    .l_btn{
        display: inline-block;
        width: 300px;
        height: 34px;
        border-radius: 17px;
        background-color: #2cc3ed;
        font-size: 18px;
        line-height: 34px;
        text-align: center;
        margin:  20px auto 0 auto;
        color: #ffffff;
    }
    .displaynone{
        display: none;
    }
    /*截图上传页面*/
    .clipbg{
        position: fixed;
        background: black;
        top: 0;
        z-index: 999;
        width: 100%;
        height: 100%;
        left: 0;
    }
    .loading{
        position: absolute;
        top: 40%;
        width: 38%;
        left: 31%;
        height: 1.6rem;
        line-height: 1.6rem;
        z-index: 99999;
        text-align: center;
        color: #ffffff;
        border-radius:0.2rem ;
        background: #9f9f9f;
    }
    .clipbg #clipArea2{
        width: 100%;
        height: 80%;
        margin: auto;

    }
    .clipbg .footer{
        width: 90%;
        position: fixed;
        left: 50%;
        bottom: .2rem;
        border-radius:.4rem; overflow:hidden;
        text-align: center;
    }
    .clipbg dl{
        overflow: hidden;

        float:left; width:66.66%;
    }
    .clipbg dd{
        position: relative;
        height: 0.9rem;
        line-height: 0.9rem;
        width:50%;
        float:left;
    }
    .clipbg .back{
        height: 0.9rem;
        line-height:0.9rem;
        background: #ffffff;
        float:left; width:33.33%;
    }
    .clipbg dd input{
        position: absolute;
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
        z-index: 11;
        filter:alpha(opacity=0);
        -moz-opacity:0;
        -khtml-opacity: 0;
        opacity: 0;
    }
    .footer1{
        height: 0.9rem !important;
    }
    .uploadNotice { position:fixed; width:100%; text-align:center; color:#FFF; font-size:12px; bottom: 1.2rem;}
    .setTitle_h a {
        display: block;
        background: url(https://css2020.yixuan.net/2020css/fcworker/images/backBtn.png) center no-repeat;
        width: 0.19rem;
        height: 0.32rem;
        background-size: 100% auto;
        position: absolute;
        top: 0.44rem;
        left: 0.12rem;
    }
    .input-border{
        height: 0.8rem;
    }
</style>
<!-- <script src="{$_G['URL']['YX2020_CSS']}js/vconsole.min.js"></script>
    <script> var vConsole = new VConsole(); </script> -->

<body style="background:#f8f8f8">
<div id="mescroll" class="mescroll">
    <div id="app">
        {if $showpage!=2 && $showpage!=9}
        <div class="setTitle_h" id="setTitle" style="overflow: hidden;word-wrap:break-word; word-break:break-all;">
            {if !empty($_P['pass'])}
            <a href="{$nopass_url}"></a>
            {/if}
            {$jubf['banquan']}・微信营销专家
        </div>
        {/if}
        {if $showpage==1}
        <form id="myform1">
            {if $autonext && !($fans['nickname']=='微信用户' || $fans['nickname']=='新用户')}
            <input type="hidden" id="pass" name="pass" value="{$_P['pass']}" />
            <input type="hidden" name="op" value="next">
            {else}
            <div class="setActive">
                <div class="actTit">
                    注册员工
                </div>
                <ul>
                    {if $shoplist && !$autonext}
                    <li id="company_list">
                        <p>所属企业</p>
                        <select id="company" name="company" >
                            <option value="0" >请选择所属企业</option>
                            {loop $shoplist $item}
                            <option value="{$item['id']}" >{$item['name']}</option>
                            {/loop}
                        </select>
                    </li>
                    {/if}
                    {if $autonext && ($fans['nickname']=='微信用户' || $fans['nickname']=='新用户')}
                    <input type="hidden" id="pass" name="pass" value="{$_P['pass']}" />
                    {else}
                    <li>
                        <p>您的操作密码</p>
                        <input type="number" class="input-border" id="pass" name="pass" value="" placeholder="请输入密码">
                    </li>
                    {/if}

<!--                    <div class="text-right">注：不同密码拥有不同权限</div>-->
                </ul>
                <input type="hidden" name="op" value="next">
                <div class="btn-div ">
                    <button class="btn" id="sub1" type="button">
                        {if $autonext && ($fans['nickname']=='微信用户' || $fans['nickname']=='新用户')}
                        授权登录
                        {else}
                        下一步
                        {/if}
                    </button>
                </div>
            </div>
            {/if}
        </form>
        {/if}
        <!--管理员添加团队-->
        <form id="myform2" style="display: none;">
            <div class="setActive">
                <div class="actTit">
                    添加团队
                </div>
                <ul id="myui2">

                </ul>
                <li><div class="group_tips" id="addTeam">注：此步若略过，不开启团队业绩统计；团队名最多5个字符</div></li>
                <ul id="myui3"></ul>
                <div class="btn-div">
                    <button class="btn" id="sub2" type="button">下一步（可略过）</button>
                </div>
            </div>
            <input type="hidden" id="tuanshu" value="0">
            <input type="hidden" id="teammax" value="0">
        </form>


        <!--员工操作密码对应-->
        <form id="myform3" style="display: none;">
            <div class="setActive">
                <div class="actTit">
                    个人信息
                </div>
                <ul id="myui4">
                    <li class="upload-img-li">
                        <p>微信二维码：</p>
                        <!--                <div class="layui-upload-drag" id="test10" style="margin: 0 auto;">-->
                        <!--                <i class="layui-icon show_tips"></i>-->
                        <!--                <p class="show_tips">点击上传，或将文件拖拽到此处</p>-->
                        <!--                <div class="layui-hide" id="uploadDemoView">-->
                        <!--                    <hr>-->
                        <!--&lt;!&ndash;                    <img src="" id="show_qrcode" alt="上传成功后渲染" style="max-width: 196px">&ndash;&gt;-->
                        <!--                    <img src="" id="bgl" alt="上传成功后渲染" style="max-width: 196px">-->
                        <!--                    </div>-->
                        <!--                <input type="hidden" name="qrcode" id="qrcode" value="">-->
                        <!--                </div>-->
                        <a class="logo" id="logox" href="javascript:uploadqr()">
                            {if empty($wechatgroup['img'])}
                            <img id="bgl" align="right"  style="width: 40px;height: 40px; " src="{$_G['URL']['YX2020_CSS']}avatar/img/headbig.png">
                            {else}
                            <img id="bgl" src="{$wechatgroup['img']}" align="right" style=" width: 2rem;height:2rem;"><input type="hidden" name="qrcode" value="{$wechatgroup['img']}" />
                            {/if}
                        </a>
                    </li>
                </ul>
                <!--        <input type="hidden" id="team" name="team" value="">-->
                <div class="btn-div martop80">
                    <button class="btn" id="sub3" type="button">下一步</button>
                </div>
            </div>
            <!--    <input type="hidden" name="server_openid" id="server_openid" value="{$server_openid}">-->
            <input type="hidden" name="server_openid" id="server_openid" value="{$_P['server_openid']}">
        </form>

        <!--生成活动海报-->
        <form id="myform4" style="display: none">
            <div style="background: #fff;">
                <div class="i_header">
                    <div style="overflow: hidden">
                        <img src="" id="s_head" class="s_head">
                    </div>
                    <h3 class="h3" id="poster_shenfen_username"></h3>
                    <h3 class="h3" id="poster_shopname"></h3>
                </div>
                <div style="text-align: center;margin: 20px auto;">
                    <img src="" class="qr_code" id="qr_code">
                </div>
                <div class="shuoming">
                    {if $system['selling_agent']==1}
                    <div style="color: red;font-size: 22px;">代理注册二维码</div>
                    <div style="color: red">发给客户扫码输入信息即可成为代理</div>
                    {else}
                    <div>员工专属二维码,可以用来做宣传海报群发使用,可统计本人业绩</div>
                    {/if}
                </div>
                <div class="item">
                    <div class="l_btn" id="gototheme" data-value="">打开活动链接,开始邀约 >></div>
                    <div class="l_btn" id="reload_write" data-value="/{php echo createMobileUrl('X_init',array('themeid'=>$themeid));}">重新编辑</div>
                </div>
            </div>
        </form>

        <div class="h110"></div>
        <!--图片裁剪-->
        <div class="clipbg displaynone">
            <div id="clipArea2"></div>
            <div class="loading displaynone">正在载入图片...</div>

            <div class="uploadNotice">上传二维码后，若不显示图片请点击此处</div>
            <div class="footer footer1">
                <dl>
                    <dd id="open1" style="background: #087b9c; color: #ffffff;border: none;">上传二维码</dd>
                    <dd id="clipBtn2" style="background:#14bbdf; color: #ffffff;border: none;">保存</dd>
                </dl>
                <input type="file" name="imageFile" id="chooseLogoImg" accept="image/gif,image/jpeg,image/jpg,image/png"
                       value="" style="display: none;" />
                <div class="back" style="background:#62d4f5;color:#ffffff;" >取消</div>
            </div>
        </div>
        {include file='yxworker/w_foot_yixuan'}
    </div>
</div>
</body>


<link rel="stylesheet" href="{$_G['URL']['YX2020_CSS']}avatar/css/intial.css" />
<script type="text/javascript" src="{$_G['URL']['YX2020_CSS']}avatar/js/camera.js/hammer.min.js" ></script>
<script type="text/javascript" src="{$_G['URL']['YX2020_CSS']}avatar/js/camera.js/lrz.all.bundle.js" ></script>
<script type="text/javascript" src="{$_G['URL']['YX2020_CSS']}avatar/js/camera.js/iscroll-zoom-min.js" ></script>
<script type="text/javascript" src="{$_G['URL']['YX2020_CSS']}avatar/js/camera.js/PhotoClip.js" ></script>
<script src='https://res.wx.qq.com/open/js/jweixin-1.3.2.js'></script>

<script type="text/javascript">

    const mescroll = new MeScroll("mescroll", {
        down: {
            auto: false,
            callback: () => {
                mescroll.endSuccess();
                setTimeout(() => {
                    window.location.reload();
                },500)
            }
        },
        up: {
            use: false
        }
    })
    $(window).keydown( function(e) {
        var key = window.event?e.keyCode:e.which;
        if(key.toString() == "13"){
            is_sub1 = false;
            sub1();

        }
    });

    wx.config({
        debug: false,
        appId: '<?php echo $wx["appId"];?>',
        timestamp: '<?php echo $wx["timestamp"];?>',
        nonceStr: '<?php echo $wx["nonceStr"];?>',
        signature: '<?php echo $wx["signature"];?>',
        jsApiList: [
            // 所有要调用的 API 都要加到这个列表中
            'chooseImage',
            'uploadImage'
        ]
    });
    wx.ready(function () {
        // 在这里调用 API
        wx.checkJsApi({
            jsApiList: ['chooseImage'], // 需要检测的JS接口列表，所有JS接口列表见附录2,
            success: function (res) {
                {if $autonext && !($fans['nickname']=='微信用户' || $fans['nickname']=='新用户')}
                sub1();
                {/if}
                // 以键值对的形式返回，可用的api值true，不可用为false
                // 如：{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
            }
        });
    });

    $(function () {
        $('#open1').on('click', function () {
            // wx.chooseImage({
            //     count: 1, // 默认9
            //     sizeType: ['comporess'], // 可以指定是原图还是压缩图，默认二者都有['original','comporess'],
            //     sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
            //     success: function (res) {
            //         // alert(111 + res.localIds[0])
            //         wx.uploadImage({
            //             localId: res.localIds[0], // 需要上传的图片的本地ID，由chooseImage接口获得
            //             isShowProgressTips: 1, // 默认为1，显示进度提示
            //             success: function (res) {
            //                 var serverId = res.serverId; // 返回图片的服务器端ID
            //                 var posturl = '{$uploadurl}'+'&bid=' + encodeURI(serverId);
            //                 // alert('=' +serverId+'=')
            //
            //                  $.ajax({
            //                       type: 'POST',
            //                       dataType : "json",
            //                       url:posturl,
            //                       data: {aid:serverId},
            //                       success: function(data) {
            //                         // alert(data);
            //                        data = data.message;
            //                          // if(data.errcode == 0){
            //                             clipArea2.load(data.remotepath)
            //                           console.log(123)
            //                          // }
            //                       },
            //                       error: function() {
            //                       }
            //                   });
            //
            //                 // $.post(posturl,{serverId:res.serverId} , function (response) {
            //                     // alert(response)
            //                     /*getUrlBase64(response,'jpg',function (blob) {
            //                         let url = window.URL.createObjectURL(dataURLtoBlob(blob))
            //
            //                         clipArea2.load(url)
            //                     })*/
            //                     // clipArea2.load(response)
            //                 // })
            //
            //                 var serverId = res.serverId; // 返回图片的服务器端ID
            //             }
            //         });
            //         // alert(222)
            //
            //         localId = res.localIds[0]
            //     }
            // });
            $("#chooseLogoImg").click();
        })
    })

        $("#chooseLogoImg").change(function (e) {
            var formdata = new FormData();
            formdata.append("file",$("#chooseLogoImg")[0].files[0]);
            var posturl = "/{php echo createMobileUrl('X_init',array('themeid'=>$themeid,'op'=>'upload'));}";
            $.ajax({
                type: 'POST',
                dataType:'json',
                url:posturl,
                data: formdata,
                contentType : false,
                processData : false,
                success: function(data) {
                    data = data.message;
                    // if(data.errcode == 0){
                    clipArea2.load(data.remotepath)
                    // }
                },
                error: function() {
                }
            });
        })


    /**
     * base64 convert blob
     * @param dataurl
     * @returns {Blob}
     */
    function dataURLtoBlob(dataurl) {
        var arr = dataurl.split(','),
            mime = arr[0].match(/:(.*?);/)[1],
            bstr = atob(arr[1]),
            n = bstr.length,
            u8arr = new Uint8Array(n);
        while (n--) {
            u8arr[n] = bstr.charCodeAt(n);
        }
        return new Blob([u8arr], {type: mime});
    }

    /**
     *
     * @param url 图片路径
     * @param ext 图片格式
     * @param callback 结果回调
     */
    function getUrlBase64(url, ext, callback) {
        var canvas = document.createElement("canvas");   //创建canvas DOM元素
        var ctx = canvas.getContext("2d");
        var img = new Image;
        img.crossOrigin = 'Anonymous';
        img.src = url;
        img.onload = function () {
            canvas.height = 60; //指定画板的高度,自定义
            canvas.width = 85; //指定画板的宽度，自定义
            ctx.drawImage(img, 0, 0, 60, 85); //参数可自定义
            var dataURL = canvas.toDataURL("image/" + ext);
            callback.call(this, dataURL); //回掉函数获取Base64编码
            canvas = null;
        };
    }
</script>
<script>
    function uploadqr() {
        $(".clipbg").fadeIn()
    }
    var clipArea2 = new  PhotoClip("#clipArea2", {
        size: [300, 300],//裁剪框大小
        outputSize:[0,0],//打开图片大小，[0,0]表示原图大小
        file: "#file2",
        ok: "#clipBtn2",
        loadStart: function() { //图片开始加载的回调函数。this 指向当前 PhotoClip 的实例对象，并将正在加载的 file 对象作为参数传入。（如果是使用非 file 的方式加载图片，则该参数为图片的 url）
            $(".loading").removeClass("displaynone");

        },
        loadComplete: function() {
            //图片加载完成的回调函数。this 指向当前 PhotoClip 的实例对象，并将图片的 <img> 对象作为参数传入。
            $(".loading").addClass("displaynone");

        },
        done: function(dataURL) { //裁剪完成的回调函数。this 指向当前 PhotoClip 的实例对象，会将裁剪出的图像数据DataURL作为参数传入。

            console.log("压缩前", dataURL.length / 1024)
            dealImage(dataURL, 300, printing);

            $('#logox').html('<img id="bgl" src="' + base64 + '" align="right" style=" width: 2rem;height:2rem;"><input type="hidden" name="qrcode" value="' + base64 + '" />');
            // console.log(dataURL);//dataURL裁剪后图片地址base64格式提交给后台处理
            $(".clipbg").fadeOut()
        }
    });
    $(".back").click(function(){
        $(".clipbg").fadeOut()
    })
    //压缩方法
    function dealImage(base64, w, callback) {
        var newImage = new Image();
        var quality = 0.8;    //压缩系数0-1之间
        newImage.src = base64;
        newImage.setAttribute("crossOrigin", 'Anonymous');  //url为外域时需要
        var imgWidth, imgHeight;
        newImage.onload = function () {
            imgWidth = this.width;
            imgHeight = this.height;
            var canvas = document.createElement("canvas");
            var ctx = canvas.getContext("2d");
            if (Math.max(imgWidth, imgHeight) > w) {
                if (imgWidth > imgHeight) {
                    canvas.width = w;
                    canvas.height = w * imgHeight / imgWidth;
                } else {
                    canvas.height = w;
                    canvas.width = w * imgWidth / imgHeight;
                }
            } else {
                canvas.width = imgWidth;
                canvas.height = imgHeight;
                quality = 0.6;
            }
            ctx.clearRect(0, 0, canvas.width, canvas.height);
            ctx.drawImage(this, 0, 0, canvas.width, canvas.height);
            var base64 = canvas.toDataURL("image/jpeg", quality); //压缩语句
            // 如想确保图片压缩到自己想要的尺寸,如要求在50-150kb之间，请加以下语句，quality初始值根据情况自定
            // while (base64.length / 1024 > 150) {
            //  quality -= 0.01;
            //  base64 = canvas.toDataURL("image/jpeg", quality);
            // }
            // 防止最后一次压缩低于最低尺寸，只要quality递减合理，无需考虑
            // while (base64.length / 1024 < 50) {
            //  quality += 0.001;
            //  base64 = canvas.toDataURL("image/jpeg", quality);
            // }
            callback(base64);//必须通过回调函数返回，否则无法及时拿到该值
        }
    }

    //使用压缩
    function printing(base64) {
        console.log("压缩后2", base64.length / 1024)
        $('#logox').html('<img id="bgl" src="' + base64 + '" align="right" style=" width: 2rem;height:2rem;"><input type="hidden" name="qrcode" value="' + base64 + '" />');
        // console.log(dataURL);//dataURL裁剪后图片地址base64格式提交给后台处理
        $(".clipbg").fadeOut()
    }
</script>
<script>
    function onBridgeReady() {
        WeixinJSBridge.call('hideOptionMenu');
    }

    if (typeof WeixinJSBridge == "undefined") {
        if (document.addEventListener) {
            document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
        } else if (document.attachEvent) {
            document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
            document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
        }
    } else {
        onBridgeReady();
    }
</script>





<script>

    $('.choseBar2 span').click(function(){
        $(this).addClass('on').siblings().removeClass('on');
    })
    $('.moreChose span').click(function(){
        if($(this).hasClass('on')){
            $(this).removeClass('on')
        }else{
            $(this).addClass('on')
        }
    })
    $("#sub1").click(function () {
        is_sub1 = false;
        sub1();
    });
    {if $autonext && !($fans['nickname']=='微信用户' || $fans['nickname']=='新用户')}setTimeout(function (){
        sub1();
    },3000);{/if}
    var is_sub1 = false;
    function sub1(){
        if (is_sub1){
            return;
        }
        is_sub1 = true;
        var forward = '{php echo $fans['nickname']=='微信用户' || $fans['nickname']=='新用户'?\app\model\Fans::get_login_url($system,$theme):'';}';
        // var forward = '{$forward}';
        if (forward){
            window.location.href=forward;
            return ;
        }

        var company = $("#company").val();
        var pass = $("#pass").val();
        // if (company==0){
        //     layer.msg('请选择所属企业！');
        //     return;
        // }
        if (!pass){
            layer.msg('操作密码不能为空！');
            return;
        }
        var postUrl="/{php echo createMobileUrl('X_init',array('themeid'=>$themeid));}";
        $.ajax({
            url:postUrl,
            dataType:'json',
            method:'post',
            data: {company:company,pass:pass,op:'next'},
            success:function (e) {
                let data = e.data;
                let error = e.error;
                let msg = e.msg;
                if (error){
                    layer.msg(msg);
                    return;
                }else{
                    $("#tuanshu").val(data.tuanshu);
                    $("#teammax").val(data.teammax);
                    if (data.showpage==2){
                        $("#myform1").hide();
                        $("#setTitle").hide();
                        $("#myform2").show();
                        if (data.shopname){
                            var ui_li = '<li>' +
                                '<p>所属企业</p>' +
                                '<input type="text" class="input-border"  value="'+data.shopname+'" readonly>' +
                                '</li>';
                            $("#myui2").append(ui_li);
                        }
                        if (data.tuanshu){
                            if (data.tuan){
                                var ui_li2 = '';


                                for (var i=1;i<=data.tuanshu;i++){
                                    ui_li2 += '<li><p>团队'+ i +'</p>';
                                    var tuan_val = ''
                                    if (data.tuan[i]){
                                        tuan_val = data.tuan[i];
                                    }
                                    if (i<=5){
                                        var pl_name = '';
                                        if (i==1){
                                            pl_name = '如:精英队';
                                        }else if(i==2){
                                            pl_name = '如:超越队';
                                        }else if(i==3) {
                                            pl_name = '如:无敌队';
                                        }else if(i==4) {
                                            pl_name = '如:微商队';
                                        }else{
                                            pl_name = '如:战狼队';
                                        }
                                        ui_li2 += '<input type="text" name="tuan'+i+'" maxlength="5" placeholder="' + pl_name + '" value="'+tuan_val+'">';
                                    }else{
                                        ui_li2 += '<input type="text" name="tuan'+i+'" maxlength="5" placeholder="请输入队名" value="'+tuan_val+'">';
                                    }
                                    ui_li2 += '</li>';
                                }


                                // $.each(data.tuan,function (i,item) {
                                //     ui_li2 += '<li><p>团队'+ i +'</p>';
                                //     if (i>5){
                                //         ui_li2 += '<input type="text" name="tuan'+i+'" placeholder="请输入队名" value="'+data.tuan[i]+'">';
                                //     }
                                //     ui_li2 += '</li>';
                                // })
                                $("#myui2").append(ui_li2);
                            }else{
                                var ui_li2 = '';
                                for (var i=1;i<=data.tuanshu;i++){
                                    ui_li2 += '<li><p>团队'+ i +'</p>';
                                    if (i<=5){
                                        var pl_name = '';
                                        if (i==0){
                                            pl_name = '如:精英队';
                                        }else if(i==1){
                                            pl_name = '如:超越队';
                                        }else if(i==2) {
                                            pl_name = '如:无敌队';
                                        }else if(i==3) {
                                            pl_name = '如:微商队';
                                        }else{
                                            pl_name = '如:战狼队';
                                        }
                                        ui_li2 += '<input type="text" name="tuan'+i+'" maxlength="5" placeholder="' + pl_name + '" value="">';
                                    }
                                    ui_li2 += '</li>';
                                }
                                $("#myui2").append(ui_li2);
                            }

                        }
                        if (data.tuanshu<data.teammax){
                            var append_html3 = '<div class="text-right" id="addTeam">点击增加5个团队</div>' +'';
                            $("#myui3").append(append_html3);
                        }
                    }else if (data.showpage==3){
                        $("#myform1").hide();
                        $("#myform2").hide();
                        $("#setTitle").show();
                        var temp_mobile = data.myworker.mobile;
                        var temp_username = data.myworker.username;
                        if (!temp_mobile || temp_mobile=='null'){
                            temp_mobile = '';
                        }
                        if (!temp_username || temp_username=='null'){
                            temp_username = '';
                        }
                        if (data.isshow_wxid){
                            var wechat_html = '<li>' +
                                '<p>微信ID：</p>' +
                                '<input type="text" placeholder="请输入微信ID,客户可快速复制添加微信"  name="wechat"  value="'+data.myworker.wechat+'}">' +
                                '</li>';
                            $("#myui4").prepend(wechat_html);
                        }
                        var username_html = '<li>' +
                            '                <p>昵称：(最长5个字符)</p>' +
                            '                <input type="text" placeholder="请输入昵称" maxlength="5"  name="username"  value="'+temp_username+'">' +
                            '            </li>';
                        var mobile_html = '<li>' +
                            '                <p>电话：</p>' +
                            '                <input type="tel" maxlength="11" placeholder="请输入电话"  name="mobile"  value="'+temp_mobile+'">' +
                            '            </li>';
                        $("#myui4").prepend(mobile_html);
                        $("#myui4").prepend(username_html);
                        if (data.teamlist.length>0){
                            var html = '<li>' +
                                '<p>请选择所属团队</p>' +
                                '<select id="team" name="team" >';
                            var ui_li4 = '';
                            $.each(data.teamlist,function (i,item) {
                                ui_li4 += '<option value="'+item.id+'" >'+item.name+'</option>';
                            })
                            var temp_bottom = '</select>' +'</li>';
                            var append_html = html+ui_li4+temp_bottom;
                            $("#myui4").prepend(append_html);
                        }
                        if (data.shopname){
                            var temp_html = '<li>' +
                                '                <p>所属企业</p>' +
                                '                <input type="text" class="input-border" value="'+ data.shopname+'" readonly>\n' +
                                '            </li>';
                            $("#myui4").prepend(temp_html);
                        }
                        if (data.myworker.qrcode){
                            $(".show_tips").hide();
                            $("#uploadDemoView").removeClass('layui-hide').find('img').attr('src', data.myworker.qrcode);
                            $("#qrcode").val(data.myworker.qrcode);
                        }
                        // $("#team").val(data.myworker.team);
                        $("#myform3").show();
                    }
                }
            },
            fail:function (err) {
                console.log(err)
            }
        });
    }
    $("#sub2").click(function () {
        var formData2 = $("#myform2").serializeArray();
        let teamlist = {};
        $.each(formData2,function (index,item) {
            teamlist[item.name] = item.value;
        });
        let json_data = JSON.stringify(teamlist);

        var company = $("#company").val();
        var postUrl="/{php echo createMobileUrl('X_init',array('themeid'=>$themeid));}";
        $.ajax({
            url:postUrl,
            dataType:'json',
            method:'post',
            data: {company:company,teamlist:json_data,op:'last'},
            success:function (e) {
                let data = e.data;
                let error = e.error;
                let msg = e.msg;
                if (error){
                    layer.msg(msg);
                    return;
                }else{
                    $("#myform2").hide();
                    $("#setTitle").show();

                    var temp_mobile = data.myworker.mobile;
                    var temp_username = data.myworker.username;
                    if (!temp_mobile || temp_mobile=='null'){
                        temp_mobile = '';
                    }
                    if (!temp_username || temp_username=='null'){
                        temp_username = '';
                    }
                    var mobile_html = '<li>' +
                        '                <p>电话：</p>' +
                        '                <input type="tel" maxlength="11" placeholder="请输入电话" name="mobile"  value="'+temp_mobile+'">' +
                        '            </li>';
                    $("#myui4").prepend(mobile_html);
                    var username_html = '<li>' +
                        '                <p>昵称：(最长5个字符)</p>' +
                        '                <input type="text" placeholder="请输入昵称" maxlength="5" name="username"  value="'+temp_username+'">' +
                        '            </li>';
                    $("#myui4").prepend(username_html);
                    if (data.teamlist.length>0){
                        var html = '<li>' +
                            '<p>请选择所属团队</p>' +
                            '<select id="team" name="team" >';
                        var ui_li4 = '';
                        $.each(data.teamlist,function (i,item) {
                            if (item.id == data.myworker.team){
                                ui_li4 += '<option value="'+item.id+'" selected>'+item.name+'</option>';
                            }else{
                                ui_li4 += '<option value="'+item.id+'" >'+item.name+'</option>';
                            }

                        })
                        var temp_bottom = '</select>' +'</li>';
                        var append_html = html+ui_li4+temp_bottom;
                        $("#myui4").prepend(append_html);
                    }
                    if (data.shopname){
                        var temp_html = '<li>' +
                            '                <p>所属企业</p>' +
                            '                <input type="text" class="input-border" value="'+ data.shopname+'" readonly>\n' +
                            '            </li>';
                        $("#myui4").prepend(temp_html);
                    }

                    if (data.isshow_wxid){
                        var wechat_html = '<li>' +
                            '<p>微信ID：</p>' +
                            '<input type="text" placeholder="请输入微信ID,客户可快速复制添加微信"  name="wechat"  value="'+data.myworker.wechat+'}">' +
                            '</li>';
                        $("#myui4").prepend(wechat_html);
                    }
                    if (data.myworker.qrcode){
                        $(".show_tips").hide();
                        $("#uploadDemoView").removeClass('layui-hide').find('img').attr('src', data.myworker.qrcode);
                        $("#qrcode").val(data.myworker.qrcode);
                    }
                    // $("#team").val(data.myworker.team);
                    $("#myform3").show();

                }
            },
            fail:function (err) {
            }
        });
    });
    $("#sub3").click(function () {
        var formData3 = $("#myform3").serializeArray();
        let teamlist = {};
        $.each(formData3,function (index,item) {
            teamlist[item.name] = item.value;
        });
        if (!teamlist['username']){
            layer.msg('请输入昵称');
            return;
        }
        var parmTel =  /^1(|3|4|5|6|7|8|9)\d{9}$/;
        if (!teamlist['mobile'] || !parmTel.test(teamlist['mobile'])){
            layer.msg('请正确输入电话');
            return;
        }
        var company = $("#company").val();
        var server_openid = $("#server_openid").val();
        teamlist['company'] = company;
        teamlist['server_openid'] = server_openid;
        teamlist['op']='save';
        // let json_data = JSON.stringify(teamlist);
        var postUrl="/{php echo createMobileUrl('X_init',array('themeid'=>$themeid));}";
        $.ajax({
            url:postUrl,
            dataType:'json',
            method:'post',
            data: teamlist,
            success:function (e) {
                let data = e.data;
                let error = e.error;
                let msg = e.msg;
                if (error){
                    layer.msg(msg);
                    return;
                }else{

                    {if $system['selling_agent']!=1 && $config['workerpass_mode']=='0'}
                        window.location.href=data.x_index;
                        return ;
                    {/if}
                    $("#myform3").hide();
                    $("#setTitle").hide();
                    // $('#qr_code').attr("src",data.img_url);
                    $('#gototheme').attr("data-value", data.workerurl);
                    $('#s_head').attr("src", data.myworker.avatar);
                    var append_sehnfen_user_html = data.shenfen + data.myworker.username;
                    $("#poster_shenfen_username").html(append_sehnfen_user_html);
                    var title1,title2,title3= '';
                    if (data.shopname){
                        title1 = data.shopname;
                    }else{
                        title1 = data.jubf.title;
                    }
                    title2 = '-';
                    if (data.teamname){
                        title3 = data.teamname;
                    }else{
                        title3 = '';
                    }
                    var append_poster_shopname = title1+title2+title3;
                    $("#poster_shopname").html(append_poster_shopname);
                    $('#qr_code').attr("src", data.img_url);
                    $("#myform4").show();
                    $(".h167").hide();

                }
            },
            fail:function (err) {
            }
        });
    });
    $("#gototheme").click(function () {
        var goto_theme_url = $("#gototheme").attr("data-value");
        self.location.href = goto_theme_url;
    });
    $("#reload_write").click(function () {
        var reload_write_url = $("#reload_write").attr("data-value");
        self.location.href = reload_write_url;
    });

    //base64  图片上传
    layui.use(['upload','element','layer'],function () {
        var $ = layui.jquery,
            upload = layui.upload,
            layer = layui.layer;
        //拖拽上传
        upload.render({
            elem: '#test10'
            ,url: '' //改成您自己的上传接口
            ,auto: false
            ,choose:function (obj) {
                // var files = obj.pushFile();
                //预读本地文件，如果是多文件，则会遍历。(不支持ie8/9)
                obj.preview(function(index, file, result){
                    // console.log(result); //得到文件base64编码，比如图片
                    $(".show_tips").hide();
                    layui.$('#uploadDemoView').removeClass('layui-hide').find('img').attr('src', result);
                    $("#qrcode").val(result);
                });
            }
        });
    });
    $(function (){
        $("#myform2").on('click','#addTeam',function () {
            var temp_tuanshu = $("#tuanshu").val();
            var temp_teammax = $("#teammax").val();
            var new_team_total = Number(temp_tuanshu)+5;
            var diff_total = 0;
            if (new_team_total<=temp_teammax){
                diff_total = 5;
            }else{
                diff_total = Number(temp_teammax)-Number(temp_tuanshu);
            }
            if (diff_total>0){
                for (var i = 1;i<=diff_total;i++){
                    var ul_li3 = '';
                    var new_num = Number(temp_tuanshu)+Number(i);
                    ul_li3 += '<li><p>团队'+ new_num +'</p>';
                    ul_li3 += '<input type="text" name="tuan'+new_num+'" maxlength="5" placeholder="请输入队名" value="">';
                    ul_li3 += '</li>';
                    $("#myui2").append(ul_li3);
                }
                var new_tuanshu = Number(temp_tuanshu)+Number(diff_total);
                $("#tuanshu").val(new_tuanshu);
                if (new_tuanshu>=temp_teammax){
                    $("#addTeam").hide();
                }
            }
        });
    });
</script>
<script type="text/javascript">
    /*禁示分享当前页面*/
    function onBridgeReady() {
        WeixinJSBridge.call('hideOptionMenu');
    }

    if (typeof WeixinJSBridge == "undefined") {
        if (document.addEventListener) {
            document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
        } else if (document.attachEvent) {
            document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
            document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
        }
    } else {
        onBridgeReady();
    }
</script>
{include file='fcworker/fc_base_foot'}
</html>
